define(function(require,exports,module){
	var aw = require("ajaxwrapper");
	
	module.exports = {
		showConsum:function(data,widget,edit){
			var pkPersonalInfo = data.pkPersonalInfo,pkChangeRoom = data.pkChangeRoom, waterElectric = data.waterElectric;
			widget.set("pkPersonalInfo", pkPersonalInfo);
			widget.get("damagesConsumpEdit").setData([]);
			widget.get("roomConsumpEdit").setData([]);
			var weForm = widget.get("waterelectricform");
			weForm.reset();
			if(waterElectric){
				weForm.setValue("waterElectric", "是"); 
				weForm.setDisabled(true);
			}else{
				weForm.setDisabled(false);
				weForm.setValue("waterElectric", "否");
			}
			if(!edit){
				weForm.setDisabled(true);
			}
			var baseprice = widget.get("baseprice");
			weForm.setValue("waterPrice",baseprice.water);
			weForm.setValue("hotWaterPrice",baseprice.hotWater);
			weForm.setValue("electricPrice",baseprice.electric);
			if(pkChangeRoom){
				aw.ajax({
	    			url: "api/changeroom/query",
	    	        data: {
	    	        	pkChangeRoom:pkChangeRoom,
		            	"fetchProperties": "*,roomPerConsumptions.*,roomPerConsumptions.goods.*"
	    	        },
	    	        dataType: "json",
	    	        success: function(data){
	    	        	if(data.length != 0){
	    	        		var consumpData = data[0].roomPerConsumptions;
	    	        		var damagesConsumpData = [],roomConsumpEditData = [];
	    	        		for(var i = 0; i < consumpData.length; i++){
	    	        			if(consumpData[i].consumptionType.key == "RoomConsumption"){
	    	        				roomConsumpEditData.push(consumpData[i]);
	    	        			}else{
	    	        				damagesConsumpData.push(consumpData[i]);
	    	        			}
	    	        		}
	    	        		weForm.setValue("checkInElectric", data[0].checkInElectric);
	    	        		weForm.setValue("checkOutElectric", data[0].checkOutElectric);
	    	        		weForm.setValue("checkInColdWater", data[0].checkInColdWater);
	    	        		weForm.setValue("checkOutColdWater", data[0].checkOutColdWater);
	    	        		weForm.setValue("checkInHotWater", data[0].checkInHotWater);
	    	        		weForm.setValue("checkOutHotWater", data[0].checkOutHotWater);
	    	        		widget.get("roomConsumpEdit").setData(roomConsumpEditData);//房内消费
	    	        		widget.get("damagesConsumpEdit").setData(damagesConsumpData);//赔偿消费
	    	        		widget.get("roomConsumpDetailGrid").setData(roomConsumpEditData);
	    	        		widget.get("damagesConsumpDetailGrid").setData(damagesConsumpData);
	    	        	}
	    	        }
	    		})
			}
		},
	};
});
